<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			function suanShu() {
				var num = document.getElementById("num").value;
				var spanResult = document.getElementById("spanResult");
				var result = 1;
				if (num = "") {
					spanResult.innerHTML = "请输入数字";
					return;
				}
				if (num < 0) {
					spanResult.innerHTML = "负数没有阶乘";
					return;
				}
				if (isNaN(num)) {
					spanResult.innerHTML = "输入的不是一个数字";
					return;
				}
				if (num == 0) {
					spanResult.innerHTML = 1;
				}
				if (num > 0) {
					for (var i = num; i>=1 ;i--) {
						result = result * i;
					}
					spanResult.innerHTML = result;
				}
			}
		</script>
		<input type="text" id="num">
		<input type="button" onclick="suanShu()" value="阶乘">
		<span id="spanResult"></span>
	</body>
</html>
